package com.swordxu.yim.android.imlib.network.common;

import com.alibaba.fastjson.JSON;
import com.swordxu.yim.android.config.ProtocolConstant;
import com.swordxu.yim.android.imlib.network.packet.base.Header;

import io.netty.channel.Channel;

/**
 * Created by 徐晓明 on 2015/1/8.
 */
public class IMPacketDispatcher {
    public static void dispatch(String buffer, Channel channel) {
        String result = null;
        if (buffer == null) {
            return ;
        }

        Header header = new Header();
        System.out.println(JSON.parseObject(buffer).get("header"));
        header = JSON.parseObject(JSON.parseObject(buffer).get("header").toString(), Header.class);
        int sid = header.getSid();
        int cid = header.getCid();

        //登录业务请求
        if(sid == ProtocolConstant.SID_LOGIN) {
            switch (cid) {
                case ProtocolConstant.CID_LOGIN_RES_MSGSERVER:
                    LoginManager.instance(channel).login(buffer);
                    break;
//                case ProtocolConstant.CID_LOGIN_RES_MSGSERVER:
//                    break;
            }
        }
    }
}
